
package com.joysuch.wwyt.core.service;

import com.joysuch.wwyt.core.bean.BaseAttachmentBean;
import com.joysuch.wwyt.core.bean.BaseImageTypeRepositoryBean;
import com.joysuch.wwyt.core.entity.BaseImageRepository;
import com.joysuch.wwyt.core.entity.BaseImageTypeRepository;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;

public interface BaseImageRepositoryService {

    BaseImageRepository findById(Long id);

    /**
     * 保存图片。执行如下操作：
     *
     * <pre>
     * 1. 将图片文件转移到imageUploadDir
     * 2. 生成缩略图。缩略图尺寸根据thumbnailWidth,thumbnailHeight定.缩略图增加thumbnailSuffix后缀
     * 3. 保存图片记录到数据库，并返回id
     * </pre>
     *
     * 文件命名方式为
     *
     * <pre>
     * 1. 源文件命名，生成UUID(去除-)+"."+扩展名
     * 2. 缩略图, 源文件+"_"+thumbnailSuffix+"."+扩展名
     * </pre>
     *
     * @param imageFile
     *            上传的图片文件
     * @param imageUploadDir
     *            图片上传目录
     * @param thumbnailSuffix
     *            缩略图后缀
     * @param thumbnailWidth
     *            缩略图宽度
     * @param thumbnailHeight
     *            缩略图高度
     * @return 图片文件ID
     * @throws IOException
     *             读写文件出现异常
     * @throws Exception
     *             读写文件出现异常
     */
    public Long saveImage(MultipartFile imageFile, String imageUploadDir, String thumbnailSuffix,
            Integer thumbnailWidth, Integer thumbnailHeight, boolean syncFlag) throws IOException, Exception;


    public Long saveRotateImage(MultipartFile imageFile, String imageUploadDir, String thumbnailSuffix,
                          Integer thumbnailWidth, Integer thumbnailHeight, boolean syncFlag) throws IOException, Exception;


    /**
     * 保存图片文件
     *
     * @param file
     * @return
     * @throws IOException
     */
    Long saveImage(File file) throws IOException;

    /**
     * 保存并获取图片信息
     * @param file
     * @return
     * @throws IOException
     */
    BaseImageRepository getSaveImage(File file) throws IOException;

    Long saveAIImage(byte[] bytes , Long tenentId , String orgCode) throws IOException;

    String generateImageUrlById(Long id);

    String generateThumbnailImageUrlById(Long id);

    BaseAttachmentBean findBeanById(Long id);

    List<BaseAttachmentBean> list(List<String> typeCodes);

    BaseImageTypeRepository saveImageTypeRepository(BaseImageTypeRepositoryBean typeBean);

    void deleteByTypeId(List<Long> typeId);

    BaseAttachmentBean findLogoImage();

    void uploadLogoImage(Long imageId);

    /**
     * 根据id查找图片的绝对路径
     * @param imageId
     * @return
     */
    String findAbsolutePathById(Long imageId);

    /**
     * 根据id集合查找图片的绝对路径
     * @param imageIds
     * @return
     */
    Map<Long, String> findByIds(List<Long> imageIds);
}
